import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询设备管理
 */
export async function pageEtpEmployeeDevicess(params) {
  const res = await request.get('/etp/etpEmployeeDevices/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部设备管理
 */
export async function listEtpEmployeeDevicess(params) {
  const res = await request.get('/etp/etpEmployeeDevices/list', { params });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询设备管理
 */
export async function getEtpEmployeeDevices(id) {
  const res = await request.get('/etp/etpEmployeeDevices/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加设备管理
 */
export async function addEtpEmployeeDevices(data) {
  const res = await request.post('/etp/etpEmployeeDevices', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改设备管理
 */
export async function updateEtpEmployeeDevices(data) {
  const res = await request.put('/etp/etpEmployeeDevices', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除设备管理
 */
export async function removeEtpEmployeeDevices(id) {
  const res = await request.delete('/etp/etpEmployeeDevices/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除设备管理
 */
export async function removeEtpEmployeeDevicess(ids) {
  const res = await request.delete('/etp/etpEmployeeDevices/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出设备管理
 */
export async function exportEtpEmployeeDevicess(params) {
  const res = await request({
    url: '/etp/etpEmployeeDevices/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `etpEmployeeDevices_${Date.now()}.xlsx`);
}
